<template>
  <view class="contacts">
    <u-search
      placeholder="请输入名字"
      v-model="keyword"
      :show-action="false"
    ></u-search>
    <view class="margintop13">
      <view class="contactsShow" v-for="i in listAll" :key="i">
        <view>
          <view class="contactsShowName">
            {{ i.name }}
            <img class="gender" :src="i.avatar" alt />
          </view>
          <view class="contactsShowaddrss margintop8">
            <text>{{ i.address }}</text>
            <text class="marginLeft4">|</text>
            <text class="marginLeft4">{{ i.gender === 1 ? "男" : "女" }}</text>
          </view>
          <view class="margintop13" v-if="i.skill">
            <text
              class="contactsShowSkill"
              :key="z"
              v-for="z in i.skill.split(',')"
              >{{ z }}</text
            >
          </view>
        </view>
        <view class="recommended" @click="tuijian(i)">推荐</view>
      </view>
      <view style="height:53px"></view>
    </view>
  </view>
</template>

<script>
import { selectByCreate, deliverRecordsAdd } from "./api";
export default {
  data() {
    return {
      recruitInfosDetailAll: {},
      listAll: [],
      keyword: ""
    };
  },
  onShow() {
    this.selectByCreateFun();
  },
  watch: {
    keyword(val) {
      this.selectByCreateFun();
    }
  },
  onLoad(e) {
    this.recruitInfosDetailAll = JSON.parse(e.recruitInfosDetailAll);
    console.log(this.recruitInfosDetailAll);
  },
  methods: {
    tuijian(e) {
      console.log(e);
      const data = {
        activeDelivery: false,
        jobSeekerName: e.name,
        recruitInfoId: this.recruitInfosDetailAll.id,
        sourceId: this.$store.state.user.sourceId,
        sourceType: this.$store.state.user.sourceType,
        jobSeekerId: e.id
      };
      deliverRecordsAdd(data)
        .then(res => {
          console.log(res);
          uni.showToast({
            title: "操作成功",
            icon: "success",
            duration: 2000
          });
          this.navigateBackFun();
        })
        .catch(err => {
          console.log(err);
        });
    },
    navigateBackFun() {
      setTimeout(function() {
        uni.navigateBack();
      }, 2000);
    },
    selectByCreateFun() {
      const data = {
        name: this.keyword,
        recruitInfoId: this.recruitInfosDetailAll.id
      };
      selectByCreate(data)
        .then(res => {
          console.log("res", res);
          this.listAll = res;
        })
        .catch(err => {
          console.log(err);
        });
    },
    addContacts() {
      uni.navigateTo({
        url: `/pages/applyJob/editApplyJob/editApplyJob`
      });
    }
  }
};
</script>

<style lang="scss">
@import "../../../styles/styles.scss";
@import "./index.scss";
</style>
